<?php
include("../db_connect.php");

$fname = mysql_real_escape_string(htmlentities(trim($_GET['fname'])));
$lname =  mysql_real_escape_string(htmlentities(trim($_GET['lname'])));
$username = mysql_real_escape_string(htmlentities(trim($_GET['username'])));
$password = mysql_real_escape_string(htmlentities(trim($_GET['password'])));
$password2 = base64_encode($password);
$contacts = mysql_real_escape_string(htmlentities(trim($_GET['contacts'])));
$gender = mysql_real_escape_string(htmlentities(trim($_GET['gender'])));
$email = mysql_real_escape_string(htmlentities(trim($_GET['email'])));
$address = mysql_real_escape_string(htmlentities(trim($_GET['address'])));
$code = $RandomNumber 	= rand(0, 9999999999); 
$type= 3;

		$sql="INSERT INTO tbl_account (username, password ,fname ,lname ,gender, contacts,address ,email , type, code)
			VALUES ('".$username."', '".$password2."', '".strtoupper($fname)."', '".strtoupper($lname)."', '".$gender."', '".$contacts."','".strtoupper($address)."','".$email."','".$type."','".$code."')";
		
	
			mysql_query($sql) or die(mysql_error());

		
		
		if (mysql_affected_rows()){
		sendemail($email,$username,$password,$code,$fname,$lname );
			echo "1";
}
			
		else	{echo "0";
	
}	
			
			
function sendemail($email,$username,$password,$code,$fname,$lname ){
$email = $email;
$username = $username;
$password = $password;
$lname =$lname;
$fname = $fname;
$query= mysql_query("SELECT email FROM tbl_account where id='1' and type ='1'");
$email2 = mysql_fetch_array($query);

// multiple recipients
$to  = $email;
// subject
$subject = 'Confirmation message';

// message
$message = '
<html>
	<head>
	
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
	<body bgcolor="#FFFFFF" text="#0000FF" link="#FF0000" style="width:100%; text-align:justify; padding:0px; margin:0px;">
  <table style="width:100%;">
        	
			<tr align="center">
            	<td bgcolor="#000000">
					<div style="background-color:#00000; height:120px;" align="left">
						<h1><a href="http://www.bascibsu.net23.net">BASCIAUTOSALES</a></h1>
					</div>
                </td>
            </tr>
			
            <tr style="background-color:#acf947;">
            	<td height="257" bgcolor="#CCCCCC">
					<p>Welcome to BASCIAUTOSALES </p>
					<table>
						<tr>
							<td>username:</td>
							<td bgcolor="#FFFFFF">'.$username.'</td>
						</tr>
						<tr>
							<td>password:</td>
							<td bgcolor="#FFFFFF">'.$password.'</td>
						</tr>
                        <tr>
							<td>Code:</td>
							<td bgcolor="#FFFFFF">'.$code.'</td>
						</tr>
                        
					</table>
				
					<p>Please keep this email for future use.</br>	
						Note: Please dont reply to this email we will not considered it;
					</p>
						</br>
					
					<p>BASCIautosales admin Contact Us to:'.$email2['email'].'</p>
			
				</td>
            </tr>
			
 		</table>	
		

    </body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers

$headers .= "From: admin@basciautosales.hol.es \r\nReply-To: ".$email2." ";

$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
//echo $mail_sent ? "Mail sent" : "Mail failed";


}			

?>

